*** This code creates the MVPF table for the pre-pop project

cap log close
clear
set more off
set type double
set linesize 150

log using "$logdir/analysis/table_mvpf.log" , replace


******************
* Prepare locals *
******************

local costs_fil      = 65.4
local ch_costs_non   = 8.2
local delta_tax1_pos = 255.7
local delta_tax1_neg = 271.3

local alphas = 3
local psis   = 3
local phis   = 4

local alpha_1 : di %3.2f 0.01
local alpha_2 : di %3.2f 0.05
local alpha_3 : di %3.2f 0.10

local psi_1 : di %3.2f 0.05
local psi_2 : di %3.2f 0.10
local psi_3 : di %3.2f 0.20

local phi_pos_1 : di %2.1f 0.0
local phi_pos_2 : di %2.1f 0.1
local phi_pos_3 : di %2.1f 0.1
local phi_pos_4 : di %2.1f 0.1

local phi_neg_1 : di %2.1f 0.0
local phi_neg_2 : di %2.1f 0.1
local phi_neg_3 : di %2.1f 0.2
local phi_neg_4 : di %2.1f 0.3



*******************
* Calculate MVPFs *
*******************

forval aa = 1/`alphas' {
	forval ps = 1/`psis' {
		forval ph = 1/`phis' {
			
			local alpha   = `alpha_`aa''
			local psi     = `psi_`ps''
			local phi_pos = `phi_pos_`ph''
			local phi_neg = `phi_neg_`ph''
			local num   =   `psi'*`costs_fil' - `psi'*(1-`psi')*`ch_costs_non' - `phi_pos'*`delta_tax1_pos' + `phi_neg'*`delta_tax1_neg'
			local denom = `alpha'*`costs_fil'                                  - `phi_pos'*`delta_tax1_pos' + `phi_neg'*`delta_tax1_neg'
			local mvpf = round(`num'/`denom',0.01)
			local mvpf_`aa'_`ps'_`ph' : di %3.2f `mvpf'
		}
	}
}


**********************
* Populate the table *
**********************

file open myfile using "$outdir/tables/mvpf.tex" , write replace

*** Header ***
file write myfile "\begin{tabular}{lccc}" _n
file write myfile "\toprule \toprule" _n


*** Panel A: Alpha 1 ***
local aa = 1
file write myfile "\emph{Panel A: implementation costs $\,\alpha=`alpha_`aa''$} &&& \\ \hline" _n
file write myfile "& \multicolumn{3}{c}{\emph{compliance burden reduction}} \\" _n
file write myfile "\emph{adjustments to pre-populated liability} & \underline{$\psi=`psi_1'$} & \underline{$\psi=`psi_2'$} & \underline{$\psi=`psi_3'$} \\" _n
forval ph = 1/`phis' {
	file write myfile "$(\phi_+,\phi_-)=(`phi_pos_`ph'',`phi_neg_`ph'')$ & `mvpf_`aa'_1_`ph'' & `mvpf_`aa'_2_`ph'' & `mvpf_`aa'_3_`ph'' \\" _n
}
file write myfile "&&& \\" _n


*** Panel B: Alpha 2 ***
local aa = 2
file write myfile "\emph{Panel B: implementation costs $\,\alpha=`alpha_`aa''$} &&& \\ \hline" _n
file write myfile "& \multicolumn{3}{c}{\emph{compliance burden reduction}} \\" _n
file write myfile "\emph{adjustments to pre-populated liability} & \underline{$\psi=`psi_1'$} & \underline{$\psi=`psi_2'$} & \underline{$\psi=`psi_3'$} \\" _n
forval ph = 1/`phis' {
	file write myfile "$(\phi_+,\phi_-)=(`phi_pos_`ph'',`phi_neg_`ph'')$ & `mvpf_`aa'_1_`ph'' & `mvpf_`aa'_2_`ph'' & `mvpf_`aa'_3_`ph'' \\" _n
}
file write myfile "&&& \\" _n


*** Panel C: Alpha 3 ***
local aa = 3
file write myfile "\emph{Panel C: implementation costs $\,\alpha=`alpha_`aa''$} &&& \\ \hline" _n
file write myfile "& \multicolumn{3}{c}{\emph{compliance burden reduction}} \\" _n
file write myfile "\emph{adjustments to pre-populated liability} & \underline{$\psi=`psi_1'$} & \underline{$\psi=`psi_2'$} & \underline{$\psi=`psi_3'$} \\" _n
forval ph = 1/`phis' {
	file write myfile "$(\phi_+,\phi_-)=(`phi_pos_`ph'',`phi_neg_`ph'')$ & `mvpf_`aa'_1_`ph'' & `mvpf_`aa'_2_`ph'' & `mvpf_`aa'_3_`ph'' \\" _n
}


*** Footer ***
file write myfile "\bottomrule \bottomrule" _n
file write myfile "\end{tabular}" _n

file close myfile


cap log close
